﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PatternFactoryAbstract
{
    class Program
    {
        static void Main(string[] args)
        {

            Factory factoryA = new FactoryA(); 
            factoryA.CreateProductMask();
            factoryA.CreateProductPhone();

            Factory factoryB = new FactoryB();
            factoryB.CreateProductMask();
            factoryB.CreateProductPhone();

            Console.ReadKey();
        }
    }



    #region 工厂类
    /// <summary>
    /// 抽象工厂应该做到生产两种产品  
    /// </summary>
    abstract class Factory
    {
        public abstract Product CreateProductPhone();
        public abstract Product CreateProductMask(); 

    }

    //A工厂专门产出两种A的产品
    class FactoryA : Factory
    {
        public override Product CreateProductMask()
        {
           return new ProductMaskA();
        } 
        public override Product CreateProductPhone()
        {
            return new ProductPhoneA();
        }
    }

    //B工厂专门产出两种B的产品
    class FactoryB : Factory
    {
        public override Product CreateProductMask()
        {
            return new ProductMaskB();
        } 
        public override Product CreateProductPhone()
        {
            return new ProductPhoneB();
        }
    }

    #endregion

    #region 具体产品

    //抽象的产品类  放入一些产品功能
    public abstract class Product
    {
        public abstract string GetName();
    }

    /// <summary>
    /// 具体产品  A厂手机
    /// </summary>
    public class ProductPhoneA : Product
    {
        public ProductPhoneA()
        { Console.WriteLine("ProductPhoneA start"); } 
        public override string GetName()
        {
            return "ProductPhoneA";
        }
    }

    /// <summary>
    /// 具体产品 A厂口罩
    /// </summary>
    public class ProductMaskA : Product
    {
        public ProductMaskA()
        { Console.WriteLine("ProductMaskA start"); } 
        public override string GetName()
        {
            return "ProductMaskA";
        }
    }


    /// <summary>
    /// 具体产品 B厂手机
    /// </summary>
    public class ProductPhoneB : Product
    {
        public ProductPhoneB()
        { Console.WriteLine("ProductPhoneB start"); }
        public override string GetName()
        {
            return "ProductPhoneB";
        }
    }

    /// <summary>
    /// 具体产品  B厂口罩
    /// </summary>
    public class ProductMaskB: Product
    {
        public ProductMaskB()
        { Console.WriteLine("ProductMaskB start"); }
        public override string GetName()
        {
            return "ProductMaskB";
        }
    }
    #endregion




}
